<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js"></script>
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
    <div class="layui-form layuimini-form"  lay-filter="example"  >
        <form  ng-app="myApp" ng-controller="customersCtrl" ng-cloak name="myForm">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label required" >项目</label>
                    <div class="layui-input-inline ">
                        <select  ng-model="data.project_id" id="project_id" lay-verify="required" name="project_id">
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">行为控制</label>
                <div class="layui-inline">
                    <table class="layui-table">
                        <colgroup>
                        <col width="150">
                        <col width="200">
                        <col>
                        </colgroup>
                        <thead>
                        <tr>
                            <th>行为</th>
                            <th>每天新增数</th>
                            <th>单次添加时间秒</th>
                            <th>列表时间秒</th>
                            <th>详情查看间隔秒</th>
                        </tr> 
                        </thead>
                        <tbody>
                        <tr  ng-repeat="(key,class) in data.class">
                            <td>{{class.title}}</td>
                            <td>                                
                                <input type="text" name="{{class.type}}newnum"  ng-model="class.newnum" autocomplete="off" class="layui-input">
                            </td>
                            <td>
                                <input type="text" name="{{class.type}}addtime"  ng-model="class.addtime" autocomplete="off" class="layui-input">
                            </td>
                            <td>
                                <input type="text" name="{{class.type}}listtime"  ng-model="class.listtime" autocomplete="off" class="layui-input">
                            </td>
                            <td>
                                <input type="text" name="{{class.type}}infotime"  ng-model="class.infotime" autocomplete="off" class="layui-input">
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <!-- lay-filter="saveBtn" -->
                    <button class="layui-btn layui-btn-normal" lay-submit   ng-click="subForm()" >确认保存</button>
                </div>
            </div>
        </form>
    </div>
    
    <script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="../../js/lay-config.js" charset="utf-8"></script>
<script>
    var app = angular.module('myApp', []);
    app.controller('customersCtrl', function ($scope, $http,$location) {
         $scope.data ={"project_id": '0',"class":[]};
         layui.use(['form','upload','http'], function () {
            var form = layui.form,
                layer = layui.layer,
                uploadInst = layui.upload,
                http  = layui.http,
                apiurl =http.api,
                $ = layui.$;
            http.verifyToken();
            var id  = http.getQueryString('id');
            if(id){
                getProject(function(){
                    projectapiIfno();
                });
            }else{
                getProject(function(){
                    $scope.data ={"project_id": '1',
                    "class":[
                        {"type":"essay","title":"文章","newnum":"0","addtime":"0","listtime":"0","infotime":"0"},
                        {"type":"essay_chapter","title":"连载文章","newnum":"0","addtime":"0","listtime":"0","infotime":"0"},
                        {"type":"likes","title":"点赞","newnum":"0","addtime":"0","listtime":"0","infotime":"0"},
                        {"type":"comments","title":"评分","newnum":"0","addtime":"0","listtime":"0","infotime":"0"},
                        {"type":"collectstatus","title":"收藏","newnum":"0","addtime":"0","listtime":"0","infotime":"0"}
                    ]};
                    $scope.$apply();
                    console.error("$scope.data",$scope.data);
                });
             
            }

            function projectapiIfno(){
                http.httpajax("Personal/projectApiList",{'id':id},"POST",function(res) {
                    if(res.code == '0000'){
                        form.render();
                        form.val('example', res.data)
                        $('#id').val(res.data.id);
                        $scope.data=res.data;
                        $scope.$apply();
                        console.error("$scope.data",$scope.data);
                    }else{
                        layer.msg(res.msg,{time:1000,icon:2});
                    }
                });
            }

            function getProject(callback){
                http.httpajax("Personal/projectList",{},"POST",function(res) {
                    if(res.code == '0000'){
                        for(var i =0;i<res.data.length;i++){
                            $("#project_id").append("<option value=\""+res.data[i].id+"\">"+res.data[i].name+"</option>");
                        }
                        layui.form.render("select");
                        callback();
                    }else{
                        layer.msg(res.msg,{time:1000,icon:2});
                    }
                });
            }

            form.on("select", function(data){
                $scope.data.project_id = data.value;
                $scope.$apply();
            });

            $scope.subForm = function () {
                var str = angular.toJson( $scope.data);//str为字符串
                var abj = JSON.parse(str);//json为对象
                http.httpajax("Personal/projectapiAdData", abj,"POST",function(res) {
                    if(res.code === '0000'){
                        layer.msg(res.msg,{time:1000,icon:1},function(){
                            // 关闭弹出层
                            layer.close();
                            window.parent.location.reload();//刷新父页面
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        });
                    }else{
                        layer.msg(res.msg,{time:1000,icon:2});
                    }
                });
            };

        });
      
        

        
    });
</script>
</body>
</html>